<?php declare(strict_types=1);

namespace App\Bac\Controller\RBAC;

use App\Abstract\Controller;
use Hyperf\Di\Annotation\Inject;
use App\Bac\Model\RBAC\Admin as DbModel;
use App\Bac\Handler\RBAC\AdminHandler as Handler;

class AdminController extends Controller
{

    #[Inject]
    public DbModel $dbModel;

    #[Inject]
    public Handler $handler;

    /**
     * 分类列表
     * @return array
     */
    public function list(): array
    {
        return $this->handler->list($this->request->query());
    }

    public function create(): array
    {
        return $this->dbModel->insertRow($this->request->all());
    }

    public function update(int $id): array
    {
        return $this->dbModel->updateRow($this->request->all(), $id);
    }

    public function updateState(int $id,int $state): array
    {
        return $this->dbModel->updateState($id,$state);
    }

    /**
     * 删除分类
     * @param int $id
     * @return array
     * @throws \Exception
     */
    public function delete(int $id): array
    {
        return $this->dbModel->deleteRow($id);
    }

}